﻿namespace ClassLibrary.DataLayer.DataObjects
{
    using ClassLibrary.BusinessLayer.BusinessObjects;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;

    public class ProjectSupervisorDAO : IProjectSupervisorDAO
    {
        public bool DeleteProjectSupervisor(ProjectSupervisor2 clsProjectSupervisor)
        {
            return clsProjectSupervisor.Save("D");
        }

        public IList<ProjectSupervisor2> GetProjectSupervisor(ProjectSupervisor2 clsProjectSupervisor)
        {
            DataTable dt = Db.GetDataTable(clsProjectSupervisor.CreateGetCommandParameters());
            clsProjectSupervisor.LoadDataToCollection(dt.Rows[0]);
            if (dt.Rows[0] == null)
            {
                throw new Exception("ProjectSupervisor ID doesn't exist");
            }
            IList<ProjectSupervisor2> list = new List<ProjectSupervisor2>();
            list.Add(clsProjectSupervisor);
            return list;
        }

        public IList<ProjectSupervisor2> GetProjectSupervisor(string ProjectCode)
        {
            ProjectSupervisor2 clsProjectSupervisor = new ProjectSupervisor2();
            clsProjectSupervisor.ProjectCode = ProjectCode;
            return this.GetProjectSupervisor(clsProjectSupervisor);
        }

        public IList<ProjectSupervisor2> GetsProjectSupervisor()
        {
            ProjectSupervisor2 clsProjectSupervisor = new ProjectSupervisor2();
            IDataReader dtReader = Db.GetDataReader(clsProjectSupervisor.CreateGetsCommandParameters());
            IList<ProjectSupervisor2> list = new List<ProjectSupervisor2>();
            while (dtReader.Read())
            {
                clsProjectSupervisor = new ProjectSupervisor2();
                clsProjectSupervisor.LoadDataToCollection(dtReader);
                list.Add(clsProjectSupervisor);
            }
            return list;
        }

        public DataTable GetsProjectSupervisor(string SPName, DbParameter[] param)
        {
            ProjectSupervisor2 clsProjectSupervisor = new ProjectSupervisor2();
            return Db.GetDataTable(clsProjectSupervisor.GetsDataReader(SPName, param));
        }

        public bool InsertProjectSupervisor(ProjectSupervisor2 clsProjectSupervisor)
        {
            return clsProjectSupervisor.Save("I");
        }

        public int InsertProjectSupervisorReturnIdentity(ProjectSupervisor2 clsProjectSupervisor)
        {
            return clsProjectSupervisor.Save("I", true);
        }

        public string InsertProjectSupervisorReturnOutput(ProjectSupervisor2 clsProjectSupervisor)
        {
            return clsProjectSupervisor.Save("I", "@ProjectSupervisorID");
        }

        public IList<ProjectSupervisor2> ListProjectSupervisor(ProjectSupervisor2 clsProjectSupervisor)
        {
            IDataReader dtReader = Db.GetDataReader(clsProjectSupervisor.CreateListCommandParameters());
            IList<ProjectSupervisor2> list = new List<ProjectSupervisor2>();
            while (dtReader.Read())
            {
                ProjectSupervisor2 clsProjectSupervisors = new ProjectSupervisor2();
                clsProjectSupervisors.LoadDataToCollection(dtReader);
                list.Add(clsProjectSupervisors);
            }
            return list;
        }

        public IList<ProjectSupervisor2> ListProjectSupervisor(string ProjectCode)
        {
            ProjectSupervisor2 clsProjectSupervisor = new ProjectSupervisor2();
            clsProjectSupervisor.ProjectCode = ProjectCode;
            return this.ListProjectSupervisor(clsProjectSupervisor);
        }

        public bool UpdateProjectSupervisor(ProjectSupervisor2 clsProjectSupervisor)
        {
            return clsProjectSupervisor.Save("U");
        }

        public int UpdateProjectSupervisor(string SPName, DbParameter[] param)
        {
            ProjectSupervisor2 clsProjectSupervisor = new ProjectSupervisor2();
            return Db.ExecuteNonQuery(clsProjectSupervisor.UpdateQuery(SPName, param));
        }
    }
}

